<template>
  <div class="fontDa">
<!--    <el-dialog :visible.sync="dialogVisible" fullscreen destroy-on-close append-to-body @close="cacel()"-->
<!--               :before-close="handleClose">-->
      <el-container>
        <el-main :style="mode=='hz'?'height:calc(100vh - 210px); padding: 0 45px;':'height:calc(100vh - 130px); padding: 0 45px;'">
          <div v-if="mode=='df'">
            <cp-xp4 ref="cpXp4" v-if="cepingpiaoVisible4" @get-mode="getModeEvent"></cp-xp4>
          </div>
          <div v-if="mode=='hz'">
            <cp-hz-pz ref="cpHz" @openXp="openXp" ></cp-hz-pz>
          </div>
        </el-main>
      </el-container>
      <div class="fontDa">
      <div class="el-icon-back arrowBtn" @click="up()" v-if="dqwz>0&&mode=='df'"></div>
      <div class="el-icon-right arrowBtn" @click="next()" v-if="mode!='hz' && (dqwz+1) < xpList.length"></div>
      </div>
      <div class="fontDa">
<!--      <div class="shuoMing" style="margin-left: 140px;" v-if="mode=='hz'">★点击“返回测评界面”按钮，可返回该张测评票进行测评分值修改。</div>-->
        <div class="flex justifyContentSpaceBetween font22" style="margin-left: 40px; margin-top:20px;" v-if="mode=='hz'">
          <div><!--★点击“返回测评界面”按钮，可返回该张测评票进行测评分值修改。--></div>
          <div class="flex justifyContentSpaceBetween " style="margin-right:60px;">
            <span><img src="/img/logo.png" width="40" height="40"></span><span class="ml10 font28">共享运营公司测评系统</span>
          </div>
        </div>
      <div class="buttomBtn">
        <!--      <span class="nextBtn">-->
        <!--        <el-button  type="primary">返回</el-button>-->
        <!--      </span>-->
        <span slot="footer" class="dialog-footer" style="position: relative;z-index: 2">
        <el-button type="primary" @click="up()" v-if="dqwz>0||mode=='hz'" class="nextBtn">{{mode=='hz'?'返回':'上一张选票'}}</el-button>
        <!-- <span v-if="xpList.length>=1&&dqwz<xpList.length&&mode!='hz'" style="float: left">评票：{{ dqwz + 1 }}/{{ xpList.length }}</span> -->
        <el-tooltip content="点击可查看所有测评对象及测评结果。" placement="top" effect="light" v-if="dqwz<xpList.length&&mode!='hz'">
          <el-button type="warning" @click="openHz()" class="nextBtn">测评结果查询</el-button>
        </el-tooltip>
        <el-button type="primary" v-if="mode=='hz'" @click="tiJiao()" class="nextBtn">提交测评</el-button>
        <el-button type="primary" @click="next()" v-if="mode!='hz' && (dqwz+1) < xpList.length" class="nextBtn">下一张选票</el-button>

<!--          <span v-if="mode!='hz'" class="ml30 yeMa">-->
<!--             {{dqwz+1}} / {{xpList.length}}-->
<!--            </span>-->
      </span>
        <span v-if="mode!='hz'" class="yeMa">
             <span class="blue"> 当前第 {{dqwz+1}} 页</span> / 共 {{xpList.length}} 页
            </span>
      </div>
      </div>
<!--    </el-dialog>-->
  </div>
</template>

<script>
import { tiJiaoHd, tiJiaoXpCode} from "@/api/ceping/cepinghdglxpxxb";
import { wdXuanPiaoNew,wdXuanPiaoXpNew,getMySheet } from "@/api/ceping/jxevalvote";
import {onlineRegister,onlineVerification} from "@/api/admin/online";
import cpXp4 from "./cpIndexXp4";
import cpHzPz from "./cpIndexHzPz";

export default {
  name: "cpIndex.vue",
  components: {
    cpXp4,
    cpHzPz
  },
  data() {
    return {
      type: "",
      hdId: null,
      xcCode: "",
      dialogVisible: false,
      xpList: [],//所有选票
      dqwz: 0,//当前位置
      mode: "df",//df或hz
      timer: null,
      sheet:{
        sheetType:0
      },
      cepingpiaoVisible4:false,
    }
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },
  methods: {
    init() {
      this.xpList = [];
      this.dqwz = 0;
      this.mode = "df";
    },
    cacel() {
      //退出全屏
      function exitFullscreen() {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.webkitExitFullscreen) {
          document.webkitExitFullscreen();
        }
      }

      clearInterval(this.timer);
      exitFullscreen();
      this.$emit('next');
    },
    //初始按会议
    initHd(hdId) {
      this.init();
      this.type = "HD";
      this.hdId = hdId;
      wdXuanPiaoNew(hdId).then(res => {
        if (res.data.data.length > 0) {
          function fullScreen() {
            var element = document.documentElement;
            if (element.requestFullscreen) {
              element.requestFullscreen();
            } else if (element.msRequestFullscreen) {
              element.msRequestFullscreen();
            } else if (element.mozRequestFullScreen) {
              element.mozRequestFullScreen();
            } else if (element.webkitRequestFullscreen) {
              element.webkitRequestFullscreen();
            }
          }

          fullScreen();
          this.dialogVisible = true;
          this.xpList = res.data.data;
          this.open(0)
        } else {
          this.$notify.closeAll();
          this.$notify.error('会议中没有选票信息')
        }
      })
    },
    //初始按选票
    initXp(xcCode) {
      onlineVerification(xcCode).then(ress=>{
        if(ress.data.data=="false"){
          this.init();
          this.type = "XP";
          this.xcCode = xcCode;
          wdXuanPiaoXpNew(xcCode).then(res => {
            if (res.data.data.length > 0) {
              function fullScreen() {
                var element = document.documentElement;
                if (element.requestFullscreen) {
                  element.requestFullscreen();
                } else if (element.msRequestFullscreen) {
                  element.msRequestFullscreen();
                } else if (element.mozRequestFullScreen) {
                  element.mozRequestFullScreen();
                } else if (element.webkitRequestFullscreen) {
                  element.webkitRequestFullscreen();
                }
              }
              this.timer = setInterval(()=>{
                onlineRegister(xcCode).then(resss=>{});
              }, 30000);
              fullScreen();
              this.dialogVisible = true;
              this.xpList = res.data.data;
              //再判断新票类型，是3-5那种票
              Promise.all([
                getMySheet(this.xpList[0].cppId).then(reses => {
                  this.sheet = reses.data.data;
                })
              ]).then(res => {
                /* 你的逻辑代码 */
                this.open(0)
              })
              // this.$nextTick(() => {
              //   this.open(0)
              // });
            } else {
              this.$notify.closeAll();
              this.$notify.error('票号中没有选票信息');
            }
          })
        }else{
          this.$notify.closeAll();
          this.$notify.error('票号正在打分，不可重复上线');
        }
      })
    },
    up() {
      if (this.mode == "hz") {
        this.mode = "df";
        //this.dqwz = this.xpList.length - 1;
        this.open(this.dqwz)
      } else {
        let yzDf = this.$refs.cpXp.yzDf();
        if (yzDf > 0) {
          this.$confirm('当前页还有“' + (yzDf == 1 ? '指标项' : '评价等次') + '”没有测评，请继续完成测评。', '提示', {
            confirmButtonText: '执行操作',
            showConfirmButton: false,
            cancelButtonText: '继续打分',
            type: 'warning'
          }).then(() => {
            if (this.dqwz == 0) {
              this.mode = "hz";
              this.openHz()
            } else {
              this.dqwz = this.dqwz - 1;
              this.open(this.dqwz)
            }
          }).catch(() => {
          })
        } else {
          if (this.dqwz == 0) {
            this.mode = "hz";
            this.openHz()
          } else {
            this.dqwz = this.dqwz - 1;
            this.open(this.dqwz)
          }
        }
      }
    },
    next() {
      if (this.mode == "hz") {
        this.mode = "df";
        this.dqwz = 0;
        this.open(this.dqwz)
      } else {
        // let yzDf = this.$refs.cpXp.yzDf();
        let yzDf = 0;
        if(this.sheet.sheetType == '3'){
          yzDf = this.$refs.cpXp3.yzDf()
        }else if(this.sheet.sheetType == '4'){
          yzDf = this.$refs.cpXp4.yzDf()
        }else{
          yzDf = this.$refs.cpXp5.yzDf()
        }
        if (yzDf > 0) {
          this.$confirm('当前页还有“' + '指标项' + '”没有测评，请继续完成测评。', '提示', {
            confirmButtonText: '执行操作',
            showConfirmButton: false,
            cancelButtonText: '继续测评',
            type: 'warning'
          }).then(() => {
            if (this.dqwz == this.xpList.length - 1) {
              this.mode = "hz";
              this.openHz()
            } else {
              this.dqwz = this.dqwz + 1;
              this.open(this.dqwz)
            }
          }).catch(() => {
          })
        } else {
          if (this.dqwz == this.xpList.length - 1) {
            this.mode = "hz";
            this.openHz()
          } else {
            this.dqwz = this.dqwz + 1;
            this.open(this.dqwz)
          }
        }
      }
    },
    openXp(id) {
      for (var i in this.xpList) {
        if (this.xpList[i].id == id) {
          this.dqwz = i * 1;
          this.open(this.dqwz);
        }
      }
    },
    open(i) {
      this.mode = "df";
      this.hdId = this.xpList[i].hdId;
      this.cepingpiaoVisible4 = true;
      this.$nextTick(() => {
        this.$refs.cpXp4.initXp(this.xpList[i].id)
      });
    },
    openHz() {
      if (this.mode == "hz") {
        this.$nextTick(() => {
          if (this.type == "HD") {
            this.$refs.cpHz.initHd(this.hdId)
          } else {
            this.$refs.cpHz.initXp(this.xcCode)
          }
        })
        return;
      }
      let yzDf = this.$refs.cpXp4.yzDf();
      if (yzDf > 0) {
        this.$confirm('当前页还有“' + (yzDf == 1 ? '指标项' : '评价等次') + '”没有测评，请继续完成测评。', '提示', {
          confirmButtonText: '执行操作',
          showConfirmButton: false,
          cancelButtonText: '继续打分',
          type: 'warning'
        }).then(() => {
          this.mode = "hz";
          this.$nextTick(() => {
            if (this.type == "HD") {
              this.$refs.cpHz.initHd(this.hdId)
            } else {
              this.$refs.cpHz.initXp(this.xcCode)
            }
          })
        }).catch(() => {
        })
      } else {
        this.mode = "hz";
        this.$nextTick(() => {
          if (this.type == "HD") {
            this.$refs.cpHz.initHd(this.hdId)
          } else {
            this.$refs.cpHz.initXp(this.xcCode)
          }
        })
      }
    },
    tiJiao() {
      this.$confirm('正式提交后将不可修改，是否确认提交测评？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.type == "HD") {
          tiJiaoHd(this.hdId).then(res => {
            if (res.data.code == "0") {
              this.$notify.success("此次测评会议已提交成功");
              this.cacel();
              this.dialogVisible = false;
            } else {
              this.$notify.closeAll();
              this.$notify.error(res.data.msg)
            }
          })
        } else {
          tiJiaoXpCode(this.xpList[0].hdId, this.xcCode).then(res => {
            if (res.data.code == "0") {
              this.$notify.success("此次测评会议已提交成功");
              this.dialogVisible = false;
              this.cacel();
            } else {
              this.$notify.closeAll();
              this.$notify.error(res.data.msg)
            }
          })
        }
      })
    },
    handleClose(done) {
      this.$confirm('您的测评还没有完成，请继续完成测评。', "提示", {
        confirmButtonText: '执行操作',
        showConfirmButton: false,
        cancelButtonText: '继续打分',
        type: 'warning'
      }).then(_ => {
        done();
      }).catch(_ => {
      });
    },
    getModeEvent(data){
      this.mode = data;
    }
  }
}
</script>

<style scoped>
</style>
